package com.example.shiwu.service;

import com.example.shiwu.db.dao.ReceiveVolEleDao;
import com.example.shiwu.db.dao.SendVoDao;
import com.example.shiwu.db.dao.SendsDao;
import com.example.shiwu.db.dao.base.BaseDaoFactory;
import com.example.shiwu.db.model.ReceiveVolEle;
import com.example.shiwu.db.model.Sends;
import com.example.shiwu.db.vo.SendVo;
import com.example.shiwu.manager.DatabaseHelper;

import java.util.ArrayList;
import java.util.List;

public class ReceiveVolEleService {

    private DatabaseHelper dbHelper;
    private ReceiveVolEleDao<ReceiveVolEle> receiveVolEleDao;
//    private SendVoDao<SendVo> sendVoDao;
    private ArrayList<Sends> listSends = new ArrayList<>();

    private static final int PAGE_SIZE = 10;
    private static final int TOTAL_PAGE = 0;

//    public List<SendVo> getAll(Integer currentPage, Integer pageSize,Integer itemId){
//        sendVoDao = BaseDaoFactory.getInstance().createBaseDao(SendVoDao.class, SendVo.class);
//        SendVo send = new SendVo();
//        List<SendVo> lis = sendVoDao.query(send,"tb_sends send left join " +
//                        " tb_receive receive on send.item_id = receive.item_id left join" +
//                        " tb_items ite on ite.id = receive.item_id left join tb_device dev on dev.item_id = ite.id",
//                new String[]{"ite.id","ite.name","dev.sn as deviceId","dev.device_type as deviceType","send.voltage","send.electricity","send.send_frequency as sendFrequency","send.send_duration as sendDuration","send.send_local as sendLocal","send.operator","receive.receive_local as receiveLocal"},
//                "ite.id =?",new String[]{String.valueOf(itemId)},"ite.id","send.create_time","",currentPage,pageSize);
//        return lis;
//    }

    /**获取单个数据
     * @param sends
     * @return
     */
//    public List<Sends> getSends(Sends sends) {
//        listSends = new ArrayList<>();
//        SendsDao = BaseDaoFactory.getInstance().createBaseDao(SendsDao.class, Sends.class);
//        listSends.addAll(SendsDao.query(sends));
//        return listSends;
//    }

    /**分页获取数据
     * @param receiveVolEle
     * @return
     */
//    public List<Sends> getSendsList(Sends sends,Integer startIndex,Integer limit) {
//        SendsDao = BaseDaoFactory.getInstance().createBaseDao(SendsDao.class, Sends.class);
//        listSends = new ArrayList<>();
//        listSends.addAll(SendsDao.query(sends,null,"create_time desc",null,startIndex,limit));
//        return listSends;
//    }

    public boolean save(ReceiveVolEle receiveVolEle) {
        receiveVolEleDao = BaseDaoFactory.getInstance().createBaseDao(ReceiveVolEleDao.class, ReceiveVolEle.class);
        long size = receiveVolEleDao.insert(receiveVolEle);
        if(size >0 ){
            return true;
        }
        return false;
    }

//    public boolean updade(Sends sends,Sends where) {
//        SendsDao = BaseDaoFactory.getInstance().createBaseDao(SendsDao.class, Sends.class);
//
//        long size = SendsDao.update(sends,where);
//        if(size >0 ){
//            return true;
//        }
//        return false;
//    }
}
